package atm.com.controller.cashdispenser;

import atm.com.pojo.Cashdispenser;
import atm.com.service.cashdispenser.CashDispenserServiceInf;
import atm.com.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.math.BigDecimal;
import java.util.List;

/**
 * AdminController class
 * @author di zhang
 * @date 2021/8/24
 */
@CrossOrigin(origins = "http://localhost:5325")
@RestController
public class CashDispenserController {
    @Autowired
    private CashDispenserServiceInf cashDispenserServiceInf;

    /**查询出所有的提款机*/
    @RequestMapping("ListCashDispenser")
    public List<Cashdispenser> ListCashDispenser(){
        return cashDispenserServiceInf.ListCashDispenser();
    }

    /**选择提款机 储存session*/
    @RequestMapping("DepositCashDispenser")
    public void DepositCashDispenser(Cashdispenser cashdispenser,HttpSession session){
        CommonUtil commonUtil=new CommonUtil();
        session.setAttribute(commonUtil.CASH_DISPENSER,cashdispenser);
    }

    /**查询提款机余额*/
    @RequestMapping("GetCashDispenserBalance")
    public BigDecimal GetCashDispenserBalance(HttpSession httpSession, CommonUtil commonUtil){
        Cashdispenser cashDispenser= (Cashdispenser) httpSession.getAttribute(commonUtil.CASH_DISPENSER);
        return cashDispenserServiceInf.GetCashDispenserBalance(cashDispenser);

    }
}
